# Daniel J. Mallinson
# 2016-01-25

#Code for cleaning original spending data

raw.data <- read.csv("AlltopicsTotalSpending2000Dollars_X_1000000.csv")
head(raw.data)
nrow(raw.data)

work.data <- raw.data[which(raw.data$RE=="R"),]
nrow(work.data)
work.data$PercentMatch <- work.data$PercentMatch*.01
work.data$spending <- work.data$TheValue*work.data$PercentMatch

sum.data <- aggregate(spending ~ FC + PolicyCode + TheYear, data=work.data, FUN=sum)
sum.data <- sum.data[which(sum.data$PolicyCode!=1),]

names(sum.data) <- c("function_code","major_topic","year","spending")

#Export to excel for calculation of percent differences
write.csv(sum.data, file="spending_totals_for_differences_calculation.csv")